var e = require("../../@babel/runtime/helpers/interopRequireDefault"),
  t = e(require("../../@babel/runtime/helpers/defineProperty")),
  a = e(require("../../@babel/runtime/regenerator")),
  r = e(require("../../@babel/runtime/helpers/asyncToGenerator")),
  base = require("../../base.js");
var items = require("../../datas/items.js");

function s(e, t) {
  var a = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var r = Object.getOwnPropertySymbols(e);
    t && (r = r.filter(function (t) {
      return Object.getOwnPropertyDescriptor(e, t).enumerable;
    })), a.push.apply(a, r);
  }
  return a;
}

function c(e) {
  for (var a = 1; a < arguments.length; a++) {
    var r = null != arguments[a] ? arguments[a] : {};
    a % 2 ? s(Object(r), !0).forEach(function (a) {
      (0, t.default)(e, a, r[a]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : s(Object(r)).forEach(function (t) {
      Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t));
    });
  }
  return e;
}

var o, d = getApp();

Page({
  data: {
    item: null,
    detailId: "",
    icons: {
      icon05: base.IMGPATH + "ic_hot.png",
      icon06: base.IMGPATH + "ic_recommended.png",
      play: base.IMGPATH + "play.png",
      back: base.IMGPATH + "back.png",
      home: base.IMGPATH + "home.png"
    },
    bg: "",
    topDistance: 0,
    backHeight: 0,
    backWidth: 0,
    leftDistance: 0,
    hasHome: !1
  },
  onLoad: function (e) {
    var t = this,
      a = e.id,
      r = d.globalData.headerBtnPosi,
      i = d.globalData.winWidth,
      n = !1;
    "1047" == d.globalData.scene && (n = !0);
    var s = r.top,
      c = i - r.right,
      o = r.height,
      u = 2 * o;
    var item = items.find((i) => {
      return i.id == parseInt(e.id)
    });
    wx.showLoading({
      title: "加载中"
    }), this.setData({
      item: item,
      topDistance: s,
      leftDistance: c,
      backWidth: u,
      backHeight: o,
      detailId: a,
      hasHome: n,
      bg: Math.ceil(5 * Math.random())
    }, function () {
      t.fetchData();
    });
  },
  fetchData: (o = (0, r.default)(a.default.mark(function e() {
    var t, r, i;
    return a.default.wrap(function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return t = this.data.detailId, e.next = 3, (0, base.ajax)({
            url: "Exam/ajax_paper_detail?id=" + t,
          });

        case 3:
          if (!e.sent) {
            wx.hideLoading();
            return e.next = "end";
          }
          (r = e.sent).code ? console.log(r) : ((i = r.data) && this.setData({
            item: i
          }), wx.hideLoading());

        case 5:
        case "end":
          return e.stop();
      }
    }, e, this);
  })), function () {
    return o.apply(this, arguments);
  }),
  changeIndex: function (e) {
    var t = e.detail,
      a = t.index,
      r = t.order,
      i = t.prevStatus,
      n = this.data.item,
      s = n.questionType,
      o = 0;
    if ("SCORE" == s)
      if ("number" == typeof r) {
        var d = n.crossHeadList[r];
        d.checked = a;
        var u = r;
        i || r < n.crossHeadList.length - 1 && (u = r + 1), o = u, d.score = parseInt(d.questionOptList[a].score);
      } else n.checked = a;
    else if ("REDIRECT" == s) {
      if ("number" == typeof r) {
        var l = n.crossHeadList[r],
          p = r;
        if (l.checked = n.checked = a, i) l.checked = n.checked = a;
        else if (l.questionOptList[a].redirectSerialNum) {
          var h = l.questionOptList[a].redirectSerialNum - 1;
          h >= 0 && (p = h, n.crossHeadList[p] && (n.crossHeadList[p].prevNumber = l.serialNum - 1));
        }
        if (o = parseInt(p), n.crossHeadList[o].questionOptList[a]) {
          var f = n.crossHeadList[o].questionOptList[a].answerSeq;
          f && (n.answerResult = f);
        }
      }
    } else n.checked = a, n.answerResult = n.crossHeadList[0].questionOptList[a].answerSeq;
    this.setData({
      item: c({}, n, {
        selected: o
      })
    });
  },
  backHandle: function () {
    wx.navigateBack({
      delta: 1
    });
  },
  backHome: function () {
    wx.reLaunch({
      url: "/pages/index/index"
    });
  },
  onShareAppMessage: function (e) {
    var t = this.data.item,
      a = t.id;
    return {
      title: t.title,
      imageUrl: t.coverImgUrl,
      path: "".concat("/pages/detail/index", "?id=").concat(a)
    };
  }
});